package com.songhq.data.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.songhq.data.bean.Figure;
import com.songhq.data.bean.PageVO;
import com.songhq.data.bean.Response;
import com.songhq.data.constant.ServiceCode;
import com.songhq.data.log.util.LogUtil;
import com.songhq.data.service.FigureService;

/**
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/figure")
public class FigureController {

	@Autowired
	private  FigureService figureService;
	

    /**
     * 列表
     * @param figure
     * @return
     */
    @GetMapping(value = "/list")
    public Response listFigures( Figure figure) {
    	try {
    		LogUtil.info("FigureController.listFigures|figure = "+ JSON.toJSONString(figure));
    		PageVO result = figureService.listFigures(figure);
            return Response.ok(result);
        } catch (Exception e) {
        	LogUtil.error(e, "FigureController.listFigures");
            return Response.error(ServiceCode.FAIL, "查询列表异常");
        }
    }
    
    /**
     * 查看详情
     * @param figureId
     * @return
     */
    @GetMapping(value = "/getOne")
    public Response getOneFigure( String figureId) {
    	try {
    		LogUtil.info("FigureController.getOneFigure|figureId = " + figureId);
    		Figure result = figureService.getOneFigure(figureId);
            return Response.ok(result);
        } catch (Exception e) {
        	LogUtil.error(e, "FigureController.getOneFigure");
            return Response.error(ServiceCode.FAIL, "查询详情异常");
        }
    }
    
   
    @GetMapping(value = "/save")
    public Response saveFigure( Figure figure) {
    	try {
    		LogUtil.info("FigureController.saveFigure|figure = " + JSON.toJSONString(figure));
    		figureService.saveFigure(figure);
            return Response.ok();
        } catch (Exception e) {
        	LogUtil.error(e, "FigureController.saveFigure");
            return Response.error(ServiceCode.FAIL, "新增异常");
        }
    }
    
    @GetMapping(value = "/update")
    public Response updateFigure( Figure figure) {
    	try {
    		LogUtil.info("FigureController.updateFigure|figure = " + JSON.toJSONString(figure));
    		figureService.updateFigure(figure);
            return Response.ok();
        } catch (Exception e) {
        	LogUtil.error(e, "FigureController.updateFigure");
            return Response.error(ServiceCode.FAIL, "修改异常");
        }
    }
    @GetMapping(value = "/delete")
    public Response deleteFigure( Figure figure) {
    	try {
    		LogUtil.info("FigureController.updateFigure|figure = " + JSON.toJSONString(figure));
    		figureService.deleteFigure(figure);
            return Response.ok();
        } catch (Exception e) {
        	LogUtil.error(e, "FigureController.updateFigure");
            return Response.error(ServiceCode.FAIL, "修改异常");
        }
    }
    
    
    
    
}
